// 无重复字符的最长子串
// 给定一个字符串 s，请你找出其中不含有重复字符的最长子串的长度

function lengthOfLongestSubstring(s: string): number {
    const n = s.length;
    if (n <= 1) return n;

    let maxlen = 1;
    let left = 0;
    let right = 0;
    const set = new Set<string>();
    while (right < n) {
        while (set.has(s[right])) {
            set.delete(s[left]);
            left++;
        }
        maxlen = Math.max(maxlen, right - left + 1);
        set.add(s[right]);
        right++;
    }

    return maxlen;
}
